package spring.cloud.tasks.executor.utils;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import spring.cloud.tasks.executor.utils.log.LogEvents;
import spring.cloud.tasks.executor.utils.log.LogUtils;

import java.util.Map;

/**
 * Util for handling alarm.
 * <p>
 * Created by jeff.zhu on 17/05/2017.
 */
@Slf4j
@Setter
@Getter
public class AlarmUtils {
    /**
     * Send alarm request to Alarm API in Console.
     */
    public static void raiseAlarm(Map<String, Object> alarmInfo, String namespace) {
        int size = SystemEnvProperties.VIP_SATURN_CONSOLE_URI_LIST.size();
        for (int i = 0; i < size; i++) {

            String consoleUri = SystemEnvProperties.VIP_SATURN_CONSOLE_URI_LIST.get(i);
            String targetUrl = consoleUri + "/rest/v1/" + namespace + "/alarms/raise";

            LogUtils.info(log, LogEvents.ExecutorEvent.COMMON,
                    "raise alarm of domain {} to url {}: {}, retry count: {}", namespace, targetUrl,
                    alarmInfo.toString(), i);

        }
    }

}
